#include "vc1dec_definitions.h"
#include "vc1mem.h"

#include <stdlib.h>
#include <string.h>

VOID_VC1* VC1Malloc(U32_VC1 size, U32_VC1 align)
{
	U32_VC1 minAlign = sizeof(VOID_VC1**);
	U8_VC1* buf = NULL;
	U8_VC1* aligned_buf = NULL;

	if(align < minAlign) align = minAlign;

	buf = (U8_VC1*)malloc(size + align - 1 + sizeof(VOID_VC1**));
	if(!buf)
	{
		aligned_buf = buf + align - 1 + sizeof(VOID_VC1**);
		aligned_buf -= ((U32_VC1)aligned_buf &(align - 1));

		memset(aligned_buf,0,size);

		*((VOID_VC1**)aligned_buf-1) = (VOID_VC1*)buf;
	}
	return aligned_buf;
}


VOID_VC1  VC1Free(VOID_VC1* mem)
{
	if(mem)
		free(*((VOID_VC1**)mem - 1));
}